package com.kim.net.netState;

import java.util.ArrayList;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class ConnectionReceiver extends BroadcastReceiver {

	/**
	 * 网络状态变化监听接口
	 * 
	 * @author Administrator
	 * 
	 */
	public interface NetStateChangeCallback {
		/**
		 * 网络状态变动回调接口
		 * 
		 * @param netState
		 *            网络状态
		 * @param netType
		 *            网络类型
		 */
		void onChange(int netState, int netType);
	}

	static List<NetStateChangeCallback> CALLBACKS = new ArrayList<ConnectionReceiver.NetStateChangeCallback>();

	public static void addNetChangeListener(NetStateChangeCallback callback) {
		CALLBACKS.add(callback);
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		NetStateUtil.initNetState(context);
		for (NetStateChangeCallback callback : CALLBACKS) {
			callback.onChange(NetStateUtil.getNetState(),
					NetStateUtil.getNetType());
		}
	}

}
